//
//  CarDetailHeaderCell.m
//  CarTown
//
//  Created by xionghao on 15/8/4.
//  Copyright (c) 2015年 熊浩. All rights reserved.
//

#import "CarDetailHeaderCell.h"
#import "HeaderModel.h"
#import "HeaderModeFrame.h"
@implementation CarDetailHeaderCell
+(instancetype)cell{
    CarDetailHeaderCell *cell=[[[NSBundle mainBundle]loadNibNamed:@"CarXiangqingTableViewCell" owner:nil options:nil]firstObject];
    return cell;
}
- (void)awakeFromNib {
    // Initialization code
    self.price.contentEdgeInsets=UIEdgeInsetsMake(2, 2, 2, 2);
    self.price.backgroundColor=[UIColor redColor];
    self.price.layer.cornerRadius=8;
    self.selectionStyle=UITableViewCellSelectionStyleNone;
}

-(void)setMode:(HeaderModeFrame *)mode{
    _mode=mode;
    HeaderModel *header=_mode.headmode;
    self.name.text=header.name;
    if ([header.is_price integerValue]==2) {
         [self.price setTitle:@"电议" forState:UIControlStateNormal];
    }else{
    [self.price setTitle:[NSString stringWithFormat:@"%@万",header.sysprice] forState:UIControlStateNormal];
    }
    self.zhidao.hidden=![header.car_source_type isEqualToString:@"中规"];
    
    if ([header.con_price integerValue]>0) {
        
        if ([header.car_source_type isEqualToString:@"中规"]&&[header.is_price integerValue]!=2) {
            float xia=[[NSString removeZero:header.con_price] floatValue] - [header.sysprice floatValue];
            
            
            NSString *strxia=
            [NSString removeZero:[NSString stringWithFormat:@"%.02f",xia]]
            ;
            
            if (xia>0) {
                if ([header.discount_scale floatValue]!=0) {
                    self.zhidao.text=[NSString stringWithFormat:@"配置价：%@万/下%@点",[NSString removeZero:header.con_price],header.discount_scale];
                }else{
                self.zhidao.text=[NSString stringWithFormat:@"配置价：%@万/下%@万",[NSString removeZero:header.con_price],strxia];
                }
            }else if (xia<0)
            {
                NSString *pricestr=[NSString removeZero:[NSString stringWithFormat:@"%.02f",-xia]];
                self.zhidao.text=[NSString stringWithFormat:@"配置价:%@万/上%@万",[NSString removeZero:header.con_price],pricestr];
            }else{
                 self.zhidao.text=[NSString stringWithFormat:@"配置价：%@万",[NSString removeZero:header.con_price]];}
            }
        else{
            self.zhidao.text=[NSString stringWithFormat:@"配置价：%@万",[NSString removeZero:header.con_price]];
        }
        
    }else{
    
    
    if ([header.car_source_type isEqualToString:@"中规"]&&[header.is_price integerValue]!=2) {
        float xia=[[NSString removeZero:header.spirce] floatValue] - [header.sysprice floatValue];
        
        
        NSString *strxia=
        [NSString removeZero:[NSString stringWithFormat:@"%.02f",xia]];
        
        if ([strxia floatValue]>0) {
            if ([header.discount_scale floatValue]!=0) {
                self.zhidao.text=[NSString stringWithFormat:@"指导价：%@万/下%@点",[NSString removeZero:header.spirce],header.discount_scale];
            }else{

            self.zhidao.text=[NSString stringWithFormat:@"指导价:%@万/下%@万",[NSString removeZero:header.spirce],strxia];
            }
        }else if ([strxia floatValue]<0)
        {
            NSString *pricestr=[NSString removeZero:[NSString stringWithFormat:@"%.02f",-xia]];
            self.zhidao.text=[NSString stringWithFormat:@"指导价:%@万/上%@万",[NSString removeZero:header.spirce],pricestr];
        }
        else{
            self.zhidao.text=[NSString stringWithFormat:@"指导价：%@万",[NSString removeZero:header.spirce]];}
    }
    else{
        
        self.zhidao.text=[NSString stringWithFormat:@"指导价：%@万",[NSString removeZero:header.spirce]];
    }

    }
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:@"yyyy-MM-dd"];
    NSDate *addtime = [NSDate dateWithTimeIntervalSince1970:[header.time integerValue]];
    self.time.text=[dateFormatter stringFromDate:addtime];
    
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
